package com.mexico.inloancash.activity;

import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;

import com.mexico.inloancash.R;
import com.mexico.inloancash.dialog.IndiaAuthDialog;
import com.mexico.inloancash.fragment.IndiaFourthStepAuthFragment;
import com.mexico.inloancash.fragment.IndiaSecondStepAuthFragment;
import com.mexico.inloancash.fragment.IndiaStepOneAuthFragment;
import com.mexico.inloancash.fragment.IndiaThirdStepAuthFragment;
import com.mexico.inloancash.india_interfacedai.IndiaDealDialogInterface;
import com.mexico.inloancash.utils.StatusBarUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 认证页
 */
public class IndiaCerActivity extends BaseActivity implements IndiaDealDialogInterface {

    List<Fragment> fragments = new ArrayList<>();

    @BindView(R.id.logon_back)
    ImageView mIndiaLBack;

    @BindView(R.id.title)
    TextView title;

    @BindView(R.id.second)
    ImageView mIndiaThe_second;

    @BindView(R.id.third)
    ImageView mIndiaThe_Third;

    @BindView(R.id.fourth)
    ImageView mIndiaThe_Fourth;

    @BindView(R.id.auth_frame)
    FrameLayout mIndiaFrameLayout;

    private int index;//判断点击的第几步
//    private IndiaAuthDialog dialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.india_activity_view_step);
        ButterKnife.bind(this);
        StatusBarUtils.setColor(this, R.color.theme);
        try {
            index = getIntent().getIntExtra("index", -1);
        } catch (Exception e) {

        }
        IndiaStepOneAuthFragment one = new IndiaStepOneAuthFragment(this);
        Bundle bundle1 = new Bundle();
        one.setArguments(bundle1);

        IndiaSecondStepAuthFragment two = new IndiaSecondStepAuthFragment(this);
        Bundle bundle2 = new Bundle();
        two.setArguments(bundle2);

        IndiaThirdStepAuthFragment thir = new IndiaThirdStepAuthFragment(this);
        Bundle bundle3 = new Bundle();
        thir.setArguments(bundle3);

        IndiaFourthStepAuthFragment four = new IndiaFourthStepAuthFragment(this);
        Bundle bundle4 = new Bundle();
        four.setArguments(bundle4);

        fragments.add(one);
        fragments.add(two);
        fragments.add(thir);
        fragments.add(four);
        if (index != -1) {
            mIndiaSetTrop(index - 1);
        }
//        dialog = new IndiaAuthDialog(this, this);
    }

    public void mIndiaUpdateTitle(String str) {
        title.setText(str);
    }

    public int mIndiaCurrentTabIndex = 0;

    public void mIndiaSetTrop(int indext) {
        switch (indext) {
            case 1:
                mIndiaThe_second.setSelected(true);
                break;
            case 2:
                mIndiaThe_second.setSelected(true);
                mIndiaThe_Third.setSelected(true);
                break;
            case 3:
                mIndiaThe_second.setSelected(true);
                mIndiaThe_Third.setSelected(true);
                mIndiaThe_Fourth.setSelected(true);
                break;
        }
        FragmentTransaction trx = getSupportFragmentManager().beginTransaction();
        if (!fragments.get(indext).isAdded()) {
            trx.add(R.id.auth_frame, fragments.get(indext));
        }
        if (mIndiaCurrentTabIndex != indext) {
            trx.hide(fragments.get(mIndiaCurrentTabIndex));
            trx.show(fragments.get(indext)).commit();
        } else {
            trx.show(fragments.get(indext)).commit();
        }
        mIndiaCurrentTabIndex = indext;
    }

    @OnClick(R.id.logon_back)
    public void onViewClicked() {
//        dialog.show();
        finish();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
//            dialog.show();
            finish();
        }
        return true;
    }

    @Override
    public void doPlay() {

    }

    @Override
    public void choose() {
        finish();
    }
}
